function BarrageObj(ele, options) {
	this.ele = ele;
	this.defaults = {
			btnControl: null,
			inputBox: null,
			eleTop: this.ele.offset().top,
			eleHeight: this.ele.height(),
			eleWidth: this.ele.width(),
			mgTop: 20,
			mgBottom: 80,
			bottom: 70,
			speed: 56,
			color: "#fa3",
			imgheight: 40,
			data: {
				text: "This is a barrage",
				img: "img/logo.jpg",
				href: ""
			}
		},
		this.options = $.extend(this.defaults, options);
}
BarrageObj.prototype = {
	init: function() {
		let _Option = this.options;
		let _Container = this.ele;
		let _This = this;
		return(function() {
			_Option.btnControl.off("click");
			_Option.btnControl.on("click", function() {
				_This.loadItem();
			});
			_Container.on("mouseover mouseout");
			_Container.on("mouseover mouseout", "div.popitem", function(e) {
				let elewidth = _Option.eleWidth;
				console.log(elewidth);
				if(e.type == "mouseover") {
					$(this).stop();
				} else {
					let itemleft = $(this).offset().left;
					let soptime = itemleft / elewidth * 15000;
					console.log(soptime);
					$(this).animate({
						left: "-" + itemleft + "px"
					}, soptime, function() {
						$(this).remove();
					});
				}
				//console.log(e);
			});
			return _This;
		})();
	},
	loadItem: function(obj) {
		let _This = this;
		let _Option = this.options;
		let _Container = this.ele;
		if(obj != null) {
			_Option.data = obj;
		}
		let itemdata = _Option.data || {};
		let imghtml = "";
		let itemimg = itemdata.img;
		if(itemimg && itemimg != "") {
			imghtml = "<img style='width: 40px; height: 40px; border-radius: 50%;border: 2px solid purple;vertical-align:middle;' src='" + itemimg + "'/>";
		}
		let divbg="";
		if(imghtml!=""){
			divbg="background-color:rgba(255,255,255,0.5);";
		}
		let labelText = $("<div class='popitem' style='"+divbg+"border-radius:20px 8px 8px 20px; position: absolute;padding:2px;color:" + getRandomColor() + ";'>"+imghtml +"<label class='height: 40px;line-height: 40px;'>" + itemdata.text + "</label></div>");
		_Container.append(labelText);
		_This.loadTimeThrow(labelText);
	},
	loadTimeThrow: function(item) {
		let _Option = this.options;
		let _Container = this.ele;
		let _left = _Option.eleWidth - item.width()-10;
		let _height = _Option.eleHeight;
		let _top = Math.random() * (_height - _Option.mgBottom) + _Option.mgTop;
		item.css({
			left: _left,
			top: _top,
			color: getRandomColor()
		});
		let timeArray = [20000, 15000, 18000, 21000];
		var time = timeArray[item.index() % 4];
		item.animate({
			left: "-" + _left + "px"
		}, time, function() {
			item.remove();
		});
	}
};

function getRandomColor() {
	return '#' + (function(h) {
		return new Array(7 - h.length).join("0") + h
	})((Math.random() * 0x1000000 << 0).toString(16))
}
//	$.fn.Barrage = function(options) {
//		var newDrop = new BarrageObj($(this), options);
//		return newDrop.init();
//	}